<?php

/**
* Dom Node wrapper
* @author J.Ducastel <fredbird@fredbird.org>
* @version
*/
class ooXmlRpcDomNode {
/*------------------------------------------------------------------------------
                                                                     constructor
------------------------------------------------------------------------------*/
    /**
    *
    * @access
    */
    function ooXmlRpcDomNode(&$node) {
        $this->__construct($node);
    }/**/

    /**
    *
    * @access
    */
    function __construct(&$node) {
        $this->node=&$node;
        $this->doc=&$this->node->owner_document();
        $this->xContext=&xpath_new_context($this->doc);
    }/**/
/*------------------------------------------------------------------------------
                                                                  public methods
------------------------------------------------------------------------------*/
    /**
    * return xpath selected node(s) from domDocument
    * @param domNode $
    * @param string xpath
    * @param bool $singleResult optional, return directly first result nodes
    * @access public
    * @return array
    */
    function getXpathNodes($xpath) {
        //echo "<p>searching $xpath from </p><pre>";
        //var_dump($this->node);
        // getting results
        if (!$results=$this->xContext->xpath_eval($xpath,$this->node)
            or count($results->nodeset)<1)
            // no results
            return false;
        //return $results->nodeset;
        $nodes=array();
        for ($n=0; $n<count($results->nodeset); $n++) {
            $node=&new ooXmlRpcDomNode($results->nodeset[$n]);
            $nodes[]=&$node;
        }
        return $nodes;
    }/**/

    /**
    * return self node's content
    * @access public
    * @return mixed
    */
    function getContent() {
        return $this->node->get_content();
    }/**/

    /**
    * sets self node's content
    * @param mixed &$content
    * @access public
    * @return bool
    */
    function setContent(&$content) {
        return $this->node->set_content($content);
    }/**/

    /**
    *
    * @param
    * @access public
    * @return
    */
    function getTagName() {
        return $this->node->tagname();
    }/**/

    /**
    * return xml dump of the node
    * @param
    * @access public
    * @return string
    * /
    function getXml() {
        if (is_a($this->node,'domdocument'))
            return $this->node->dump_mem();
        return $this->node->dump_node($this->doc);
    }/**/

    /**
    * return domDocument reference
    * @access public
    * @return domDocument
    */
    function & getDomDoc() {
        return $this->doc;
    }/**/

    /**
    * build, append and return node's child
    * @param string tagName
    * @access public
    * @return & ooXmlRpcDomNode
    */
    function & makeChild($tagName) {
        // build dom node
        $dom=$this->doc->create_element($tagName);
        //append domnode
        $this->node->append_child($dom);
        $node=&new ooXmlRpcDomNode($dom);
        return $node;
    }/**/

    /**
    *
    * @param
    * @access public
    * @return
    * /
    function () {

    }/**/
/*------------------------------------------------------------------------------
                                                                      properties
------------------------------------------------------------------------------*/
    /**
    * @var type desc
    */
    var $node;
    var $doc; // root domDocument reference
    var $xContext; // xpathcontext instance
}
?>
